package com.autumn.annotations.bean.config.condition;

import com.autumn.xa.common.util.FrameworkUtils;
import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.env.Environment;
import org.springframework.core.type.AnnotatedTypeMetadata;

/**
 * ClassName: WindowsCondition
 *
 * @Description: 判断windows的
 * @Author: wangqiuyang
 * @Date: 2021/12/28 下午5:24
 * History:
 * <author>          <time>          <version>          <desc>
 * wangqiuyang    2021/12/28 下午5:24   @Version 1.0        描述
 */
public class WindowsCondition implements Condition {
    @Override
    public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {

        // 获取当前环境
        Environment environment = context.getEnvironment();

        // 通过环境获取操作系统名称
        String osName = FrameworkUtils.getOsName(environment);

        // 如果是linux 注入
        if (osName.contains("windows")) {
            return true;
        }
        return false;
    }
}
